﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DeVetma.admin.classes;
using DeVetma.admin.models.database;
using DeVetma.admin.models.entities;
using DeVetma.admin.models.managers;

namespace DeVetma.admin.test
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // doTestScript1();
            // doTestScript2();
            cleanup();
        }

        private void doTestScript1()
        {
            cleanup();

            Clothes clothe = new Clothes();
            clothe.cColor = "yellow";
            clothe.cCost = 6.00M;
            clothe.cDescription = "good";
            clothe.cHips = "15";
            clothe.cLength = "15";
            clothe.cMaterial = "cotton";
            clothe.cModelImg = "1";
            clothe.cPic1 = "2";
            clothe.cPic2 = "3";
            clothe.cPic3 = "4";
            clothe.cQuanOnHand = 15;
            clothe.cSelling = 16.00M;
            clothe.cShoulder = "6";
            clothe.cStatus = clothe.status(Clothes.ClothesStatus.Available);
            clothe.cTryImg = "7";
            clothe.cType = "0";
            clothe.cViewImg = "asd";
            clothe.cWaist = "25";
            output.Text = "ClotheManager: " + new ClothesManager().add(clothe) + " - " + clothe.cID;

            Delivery delivery = new Delivery();
            delivery.dID = Utilities.randomizeNumericString(6);
            delivery.dDate = DateTime.Now;
            delivery.dNewTel = "123456";
            delivery.dReceipent = "recipient";
            delivery.dAdd = "some address";
            output.Text += "<br/>" + "DeliveryManager: " + new DeliveryManager().add(delivery);

            Member member = new Member();
            member.mUsername = Utilities.randomizeString(10);
            member.mActivationCode = "asd";
            member.mActivationStatus = "zxc";
            member.mAdd = "some addr";
            member.mEmail = "some email";
            member.mFName = "fname";
            member.mLName = "lname";
            member.mTel = "123456";
            output.Text += "<br/>" + "MemberManager: " + new MemberManager().add(member);

            Order order = new Order();
            order.mUsername = member.mUsername;
            order.oDate = DateTime.Now;
            order.oStatus = (int)Order.OrderStatus.Cart;
            output.Text += "<br/>" + "OrderManager: " + new OrderManager().add(order) + " - " + order.oID;

            output.Text += "<br/>" + "OrderDetails Added: " + order.addOrderDetails(clothe.cID, 6);
            output.Text += "<br/>" + "New Qty for Clothe1: " + (clothe = order.orderDetails.FirstOrDefault().clothe).cQuanOnHand;
            output.Text += "<br/>" + "Adjust Qty for OD1: " + order.updateOrderDetails(clothe.cID, 7) + " - " + (clothe = order.orderDetails.FirstOrDefault().clothe).cQuanOnHand;

            OrderDetails ods = order.orderDetails.FirstOrDefault();
            ods.odQuantity = 4;
            output.Text += "<br/>" + "Update Qty through OrderDetails item: " + new OrderDetailsManager().update(ods) + " - " + order.orderDetails.FirstOrDefault().odQuantity;

            Payment payment = new Payment();
            payment.dID = delivery.dID;
            payment.mID = member.mUsername;
            payment.oID = order.oID;
            payment.pCcNum = "a";
            payment.pCctype = "b";
            payment.pCHolderName = "c";
            payment.pCVC = "d";
            payment.pDate = DateTime.Now;
            payment.pExpireDate = "e";
            payment.pID = Utilities.randomizeNumericString(6);
            payment.pNewEmail = "f";
            payment.pTotalPayment = 15.00M;
            output.Text += "<br/>" + "PaymentManager: " + new PaymentManager().add(payment);
            output.Text += "<br/>" + "[Payment]order: " + payment.order.oID;
            output.Text += "<br/>" + "[Payment]member: " + payment.member.mUsername;

            Staff staff = new Staff();
            staff.sUsername = member.mUsername;
            staff.sEmail = "a";
            staff.sFName = "fname";
            staff.sLName = "lname";
            staff.sStatus = staff.status(Staff.StaffStatus.Active);
            staff.sTel = "123456";
            output.Text += "<br/>" + "StaffManager: " + new StaffManager().add(staff);

            User user = new User();
            user.uUsername = member.mUsername;
            user.uPassword = "123456";
            user.uRole = "some role";
            output.Text += "<br/>" + "UserManager: " + new UserManager().add(user);

        }

        private static void cleanup()
        {
            Database.instance().deleteAll<Clothes>();
            Database.instance().deleteAll<Delivery>();
            Database.instance().deleteAll<Member>();
            Database.instance().deleteAll<Order>();
            Database.instance().deleteAll<OrderDetails>();
            Database.instance().deleteAll<Payment>();
            Database.instance().deleteAll<Staff>();
            Database.instance().deleteAll<User>();
        }

        private void doTestScript2()
        {
            cleanup();

            Clothes clothe = new Clothes();
            clothe.cColor = "yellow";
            clothe.cCost = 6.00M;
            clothe.cDescription = "good";
            clothe.cHips = "15";
            clothe.cLength = "15";
            clothe.cMaterial = "cotton";
            clothe.cModelImg = "1";
            clothe.cPic1 = "2";
            clothe.cPic2 = "3";
            clothe.cPic3 = "4";
            clothe.cQuanOnHand = 15;
            clothe.cSelling = 16.00M;
            clothe.cShoulder = "6";
            clothe.cStatus = clothe.status(Clothes.ClothesStatus.Available);
            clothe.cTryImg = "7";
            clothe.cType = "0";
            clothe.cViewImg = "asd";
            clothe.cWaist = "25";
            output.Text = "ClotheManager: " + new ClothesManager().add(clothe) + " - " + clothe.cID;

            Member member = new Member();
            member.mUsername = Utilities.randomizeString(10);
            member.mActivationCode = "asd";
            member.mActivationStatus = "zxc";
            member.mAdd = "some addr";
            member.mEmail = "some email";
            member.mFName = "fname";
            member.mLName = "lname";
            member.mTel = "123456";
            output.Text += "<br/>" + "MemberManager: " + new MemberManager().add(member);

            Order order = new Order();
            order.mUsername = member.mUsername;
            order.oDate = DateTime.Now;
            order.oStatus = (int)Order.OrderStatus.Cart;
            output.Text += "<br/>" + "OrderManager: " + new OrderManager().add(order) + " - " + order.oID;

            output.Text += "<br/>" + "OrderDetails Added: " + order.addOrderDetails(clothe.cID, 6);
            output.Text += "<br/>" + "Delete order details: " + order.deleteOrderDetails(clothe.cID) + " - " + new ClothesManager().get(clothe.cID).cQuanOnHand;
        }
    }
}